<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.PurreqDAO"%>
<%@page import="db.Purreq"%>
<%@page import="db.PurmatDAO"%>
<%@page import="db.UserDAO"%>
<%@page import="db.User"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	PurreqDAO purreqDao = (PurreqDAO)ctx.getBean("PurreqDAO");
	PurmatDAO purmatDao = (PurmatDAO)ctx.getBean("PurmatDAO");
	UserDAO userDao = (UserDAO)ctx.getBean("UserDAO");

	String idStr = request.getParameter("id");
	int id = 0;
	
	try{
		id = Integer.parseInt(idStr);
	}catch(Exception e){
		id = 0;
	}
	
	request.setAttribute("id",id);
	
	Purreq purreq = purreqDao.findById(id);
	request.setAttribute("purreq",purreq);
	
	List purmats = purmatDao.findByPurreqIdAndState(new Object[]{id, 1});
	request.setAttribute("purmats",purmats);
	
	User reqUser = userDao.findById(purreq.getReqUserId());
	request.setAttribute("reqUser",reqUser);
	
	User buyUser = userDao.findById(purreq.getBuyUserId());
	request.setAttribute("buyUser",buyUser);
	
	User costUser = userDao.findById(purreq.getCostUserid());
	request.setAttribute("costUser",costUser);
	
	pageContext.forward("/vm/procure/procureApp_3.vm");
%>